//
//  TUIKit.m
//  TUIKit
//
//  Created by kennethmiao on 2018/10/12.
//  Copyright © 2018年 kennethmiao. All rights reserved.
//

#import "TUIKit.h"
#import "THeader.h"
#import <ImSDK_Plus/ImSDK_Plus.h>


@interface TUIKit ()
@property (nonatomic, strong) TUIKitConfig *config;
@end

@implementation TUIKit
+ (instancetype)sharedInstance
{
    static TUIKit *instance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[TUIKit alloc] init];
    });
    return instance;
}

- (void)initV2IMSDKWithConfig:(TUIKitConfig *)config
{
    _config = config;
    
    NSFileManager *fileManager = [NSFileManager defaultManager];
    if(![fileManager fileExistsAtPath:TUIKit_Image_Path]){
        [fileManager createDirectoryAtPath:TUIKit_Image_Path withIntermediateDirectories:YES attributes:nil error:nil];
    }
    if(![fileManager fileExistsAtPath:TUIKit_Video_Path]){
        [fileManager createDirectoryAtPath:TUIKit_Video_Path withIntermediateDirectories:YES attributes:nil error:nil];
    }
    if(![fileManager fileExistsAtPath:TUIKit_Voice_Path]){
        [fileManager createDirectoryAtPath:TUIKit_Voice_Path withIntermediateDirectories:YES attributes:nil error:nil];
    }
    if(![fileManager fileExistsAtPath:TUIKit_File_Path]){
        [fileManager createDirectoryAtPath:TUIKit_File_Path withIntermediateDirectories:YES attributes:nil error:nil];
    }
    if(![fileManager fileExistsAtPath:TUIKit_DB_Path]){
        [fileManager createDirectoryAtPath:TUIKit_DB_Path withIntermediateDirectories:YES attributes:nil error:nil];
    }
    // 初始化 config 对象
    V2TIMSDKConfig *v2config = [[V2TIMSDKConfig alloc] init];
    // 指定 log 输出级别
    v2config.logLevel = V2TIM_LOG_INFO;
    // 设置 log 监听器
    v2config.logListener = ^(V2TIMLogLevel logLevel, NSString *logContent) {
        // logContent 为 SDK 日志内容
    };
    [[V2TIMManager sharedInstance]initSDK:TXIMSdkAppid config:v2config];
    
}
- (TUIKitConfig *)getConfig
{
    return _config;
}
@end
